from DataTest.sql.data_sql import sqlCheck
from request_tracking_interface import build_request_body, send_request


def data_event_sql__insert_data(event_key: str):
    """
    测试环境数据库插入埋点
    :param event_key: 埋点的key
    :return: None
    """
    sql = f"""INSERT INTO dataevents (biz, `key`, status, username, zh_name, appv, note, note_for_params, create_time, params_status,update_time) VALUES ('suki', '{event_key}', 'ok', 'testuser', 'TEST', '3.5.0', '具体备注内容', '测试', '2023-09-22 12:33:46', '','2023-09-22 12:33:46');"""
    sqlCheck(sql, 'cf_family')


def get_data_event_self_update_data() -> list:  # 获取上传的key
    sql = 'SELECT `key` FROM dataevents WHERE username="testuser"'
    response = sqlCheck(sql, 'cf_family')
    return [i[0] for i in response]


def main():
    data = get_data_event_self_update_data()
    dic = {key: {"name": "测试"} for key in data}
    body = build_request_body(dic)
    send_request(body)


if __name__ == '__main__':
    # print(data_event_sql__insert_data("TEST.XIERIJI.CK"))
    # print(get_data_event_self_update_data())
    main()